package com.tianji.promotion.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.promotion.domain.dto.CouponFormDTO;
import com.tianji.promotion.domain.dto.CouponIssueFormDTO;
import com.tianji.promotion.domain.query.CouponQuery;
import com.tianji.promotion.domain.vo.CouponDetailVO;
import com.tianji.promotion.domain.vo.CouponPageVO;
import com.tianji.promotion.domain.vo.CouponVO;
import com.tianji.promotion.service.ICouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 优惠券的规则信息 前端控制器
 * </p>
 *
 * @author zhongweiwei
 * @since 2023-06-03
 */

@RestController
@RequestMapping("/coupons")
@Slf4j
@Api(tags = "优惠卷相关接口")
@RequiredArgsConstructor
public class CouponController {
    private final ICouponService iCouponService;

    @PostMapping
    @ApiOperation("新增优惠卷接口")
    public void saveCoupon(@RequestBody @Valid CouponFormDTO dto){
        iCouponService.saveCoupon(dto);

    }
    @GetMapping("page")
    @ApiOperation("分页查询优惠卷接口")
    public PageDTO<CouponPageVO>pageQueryCoupon(CouponQuery query ){
        return iCouponService.pageQueryCoupon(query);
    }

    @PutMapping("{id}/issue")
    @ApiOperation("发放优惠卷接口")
    public void issueCoupon(@RequestBody @Valid CouponIssueFormDTO issueFormDTO){
        iCouponService.issueCoupon(issueFormDTO);
    }
    @PutMapping("{id}")
    @ApiOperation("修改优惠卷接口")
    public void recomposeCouponById(
            @ApiParam("优惠卷id") @PathVariable("id") Long id,
              @RequestBody CouponFormDTO dto){
        //优惠券id，新增不需要添加，更新必填
        dto.setId(id);
        iCouponService.recomposeCouponById(dto);
    }
    @DeleteMapping ("{id}")
    @ApiOperation("删除优惠卷接口")
    public void deleteCouponById(
            @ApiParam("优惠卷id")@PathVariable("id") Long id){
        iCouponService.deleteCouponById(id);
    }
    @GetMapping("{id}")
    @ApiOperation("根据id查询优惠卷详细信息接口")
    public CouponDetailVO inquiriesById(
            @ApiParam("优惠卷id")
            @PathVariable("id") Long id){
           return iCouponService.inquiriesById(id);
    }

//         @GetMapping("{id}")
//    @ApiOperation("根据id查询优惠卷接口用于回显")
//    public CouponDetailVO  getByCouponId(
//            @ApiParam("优惠卷id")
//            @PathVariable("id") Long id){
//        return iCouponService.getByCouponId(id);
//    }


    @PutMapping("{id}/pause")
    @ApiOperation("暂停发放优惠卷状态")
    public void changeStatusById(@ApiParam("id") @PathVariable("id") Long id){
        iCouponService.changeStatusById(id);
    }


    @GetMapping("/list")
    @ApiOperation("查询发放中的优惠卷")
    public List<CouponVO>queryAllCoupons(){
        return iCouponService.queryAllCoupons();
    }
}
